package dao;

import entity.StationEntity;
import org.apache.commons.collections.map.HashedMap;
import util.IRowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/9.
 */
public class StationDao {
    private DBHelper<StationEntity> dbHelper=new DBHelper<StationEntity>();
    //出发地，目的地查询车票价格车次
    public Map<String,Object> querySitePrice(String startStation, String endStation, String stationNum) throws SQLException, ClassNotFoundException {
        String sql="SELECT s1.trainNum trainNum,s1.station startStation,s2.station terminalStation,s2.sitePrice-s1.sitePrice as sitePrice FROM station s1,station s2 WHERE s1.trainNum=s2.trainNum AND " +
                "s1.station=? AND s2.station=? AND s1.trainNum=? ";

            ResultSet rs = dbHelper.executequery(sql, startStation, endStation, stationNum);
            Map<String,Object> result=new HashedMap();
            if(rs.next()){
                result.put("trainNum",rs.getString("trainNum"));
                result.put("startStation",rs.getString("startStation"));
                result.put("terminalStation",rs.getString("terminalStation"));
                result.put("sitePrice",rs.getFloat("sitePrice"));
            }

            return result;
    }
    public void close()throws SQLException{
        dbHelper.close();
    }
}
